<template>
	<view>
		<form>
			<view class="cu-form-group margin-top">
				<view class="title">原手机号</view>
				<input  name="input" :value="vpo" :disabled="true"></input>
			</view>
			<view class="cu-form-group solid-bottom">
				<view class="title">验证码</view>
				<input placeholder="输入获取到的验证码" name="input" v-model='code'></input>
				<button class='cu-btn bg-green shadow' :disabled="disab" @tap="getYzm">{{yzmStatus}}</button>
			</view>
			<view class="padding">
				<button class="cu-btn bg-blue margin-tb-sm lg" style="width: 100%;" @tap="geteditpass">去修改</button>
			</view>
		</form>
	</view>
</template>

<script>
	var yzmTime=59,yzmEnable=true;
	export default {
		data() {
			return {
				yzmStatus:"获取验证码",
				disab:false,
				code:null,
				vpo:null
			}
		},
		onLoad() {
			let gv=JSON.parse(uni.getStorageSync("users"))
			this.vpo=gv.mobile
		},
		methods: {
			downTimer:function(){
				var that=this;
				var it=setInterval(function(){
					yzmEnable=false;
					that.yzmStatus="倒计时"+yzmTime+"秒";
					yzmTime--;
					if(yzmTime==0){
						yzmTime=59;
						yzmEnable=true;
						that.disab=false;
						that.yzmStatus="获取验证码";
						clearInterval(it);
					}
				},1000);
			},
			geteditpass(){
				var that=this;
				if(this.code==null){
					that.app.showMsg("请输入验证码");
					return;
				}
				uni.showLoading({
					mask:true
				})
				
				uni.request({
					url:that.app.apiHost+"/editpasscode",
					method:"POST",
					header:{'Authorization':'bearer '+that.app.getAuthCode()},
					data:{code:that.code,type:'editphone'},
					success:function(res){
						uni.hideLoading()
						if(res.data.code == -1){
							that.app.showMsg('请登陆后再操作!','../login/login');
						}
						if(res.data.code==0){
							
							uni.navigateTo({
								url:"editphone"
							})
						}else{
							that.app.showMsg(res.data.msg);
						}
					}
				})
			},
			getYzm:function(){
					if(!yzmEnable) return false;
					var that=this;
					uni.request({
						url:that.app.apiHost+"/sendMsg",
						method:"POST",
						header:{'Authorization':'bearer '+that.app.getAuthCode()},
						data:{type:'editphone'},
						success:function(res){
							if(res.data.code==-1){
								that.app.showMsg('请登陆后再操作!','../login/login');
							}
							that.app.showMsg(res.data.msg);
							if(res.data.code==0){
								that.disab=true;
								that.downTimer();
							}
						}
					})
			},
		}
	}
</script>

<style>

</style>
